package org.leviatan.dataharbour.core.register;

import java.util.HashMap;
import java.util.TreeSet;

import org.leviatan.dataharbour.core.model.DataEntity;
import org.leviatan.dataharbour.core.model.DataSource;
import org.leviatan.dataharbour.core.model.HarbourRequest;
import org.leviatan.dataharbour.core.model.PersistenceResource;
import org.leviatan.dataharbour.core.model.Sender;

/**
 * Singleton design pattern class
 * 
 * @author Leviatan
 * 
 */
public class Register {
	
	
	
	private static Register instance;
	
	
	
	/* Models cache */
	///////////////////////////////////////////////////////////////////////////
	
	private HashMap<String, DataSource> dataSourceModels;
	private HashMap<String, HarbourRequest> harbourRequestModels;
	private HashMap<String, PersistenceResource> persistenceResourceModels;
	private HashMap<String, DataEntity> dataEntityModels;
	private HashMap<String, Sender> senderModels;
	
	
	/* <String(id)> */ 
	private TreeSet<String> unpersistedHarbourRequestIds;
	private TreeSet<String> harbourRequestIds;
	private TreeSet<String> dataEntityIds;
	
	
	/* Mappings: String keys to String keys */
	///////////////////////////////////////////////////////////////////////////
	
	private HashMap<String, TreeSet<String>> harbourRequestId2DataEntityIds;
	/* one-to-many */
	private HashMap<String, TreeSet<String>> dataEntityId2DefinatorFieldIds;
	/* one-to-many */
	private HashMap<String, TreeSet<String>> dataSourceId2DefinatorTableIds;
	/* one-to-many */
	private HashMap<String, TreeSet<String>> dataSourceId2PersistenceResourceIds;
	/* one-to-many */
	private HashMap<String, TreeSet<String>> senderId2DataSourceIds;
	/* one-to-many */
	private HashMap<String, TreeSet<String>> senderId2HarbourRequestIds;
	
	
	

	
	private Register() {
		
		this.dataSourceModels = new HashMap<String, DataSource>();
		this.harbourRequestModels = new HashMap<String, HarbourRequest>();
		this.persistenceResourceModels = new HashMap<String, PersistenceResource>();
		this.dataEntityModels = new HashMap<String, DataEntity>();
		
		this.unpersistedHarbourRequestIds = new TreeSet<String>();
		this.harbourRequestIds = new TreeSet<String>();
		this.dataEntityIds = new TreeSet<String>();
		
		this.harbourRequestId2DataEntityIds = new HashMap<String, TreeSet<String>>();
		this.dataEntityId2DefinatorFieldIds = new HashMap<String, TreeSet<String>>();
		this.dataSourceId2DefinatorTableIds = new HashMap<String, TreeSet<String>>();
		this.dataSourceId2PersistenceResourceIds = new HashMap<String, TreeSet<String>>();
		this.senderId2DataSourceIds = new HashMap<String, TreeSet<String>>();
		this.senderId2HarbourRequestIds = new HashMap<String, TreeSet<String>>();
		
	}
	
	public static Register getInstance() {
		if (Register.instance == null) {
			Register.instance = new Register();
		}
		return Register.instance;
	}
	
	
	
	
	///////////////////////////////////////////////////////////////////////////	
	// all gets + sets of field variables
	///////////////////////////////////////////////////////////////////////////

	
	/**
	 * @return the dataEntityId2DefinatorFieldIds
	 */
	public HashMap<String, TreeSet<String>> getDataEntityId2DefinatorFieldIds() {
		return this.dataEntityId2DefinatorFieldIds;
	}

	/**
	 * @param dataEntityId2DefinatorFieldIds the dataEntityId2DefinatorFieldIds to set
	 */
	public void setDataEntityId2DefinatorFieldIds(
			HashMap<String, TreeSet<String>> dataEntityId2DefinatorFieldIds) {
		this.dataEntityId2DefinatorFieldIds = dataEntityId2DefinatorFieldIds;
	}

	/**
	 * @return the dataEntityIds
	 */
	public TreeSet<String> getDataEntityIds() {
		return this.dataEntityIds;
	}

	/**
	 * @param dataEntityIds the dataEntityIds to set
	 */
	public void setDataEntityIds(TreeSet<String> dataEntityIds) {
		this.dataEntityIds = dataEntityIds;
	}

	/**
	 * @return the dataEntityModels
	 */
	public HashMap<String, DataEntity> getDataEntityModels() {
		return this.dataEntityModels;
	}

	/**
	 * @param dataEntityModels the dataEntityModels to set
	 */
	public void setDataEntityModels(HashMap<String, DataEntity> dataEntityModels) {
		this.dataEntityModels = dataEntityModels;
	}

	/**
	 * @return the dataSourceId2DefinatorTableIds
	 */
	public HashMap<String, TreeSet<String>> getDataSourceId2DefinatorTableIds() {
		return this.dataSourceId2DefinatorTableIds;
	}

	/**
	 * @param dataSourceId2DefinatorTableIds the dataSourceId2DefinatorTableIds to set
	 */
	public void setDataSourceId2DefinatorTableIds(
			HashMap<String, TreeSet<String>> dataSourceId2DefinatorTableIds) {
		this.dataSourceId2DefinatorTableIds = dataSourceId2DefinatorTableIds;
	}

	/**
	 * @return the dataSourceId2PersistenceResourceIds
	 */
	public HashMap<String, TreeSet<String>> getDataSourceId2PersistenceResourceIds() {
		return this.dataSourceId2PersistenceResourceIds;
	}

	/**
	 * @param dataSourceId2PersistenceResourceIds the dataSourceId2PersistenceResourceIds to set
	 */
	public void setDataSourceId2PersistenceResourceIds(
			HashMap<String, TreeSet<String>> dataSourceId2PersistenceResourceIds) {
		this.dataSourceId2PersistenceResourceIds = dataSourceId2PersistenceResourceIds;
	}

	/**
	 * @return the dataSourceModels
	 */
	public HashMap<String, DataSource> getDataSourceModels() {
		return this.dataSourceModels;
	}

	/**
	 * @param dataSourceModels the dataSourceModels to set
	 */
	public void setDataSourceModels(HashMap<String, DataSource> dataSourceModels) {
		this.dataSourceModels = dataSourceModels;
	}

	/**
	 * @return the harbourRequestId2DataEntityIds
	 */
	public HashMap<String, TreeSet<String>> getHarbourRequestId2DataEntityIds() {
		return this.harbourRequestId2DataEntityIds;
	}

	/**
	 * @param harbourRequestId2DataEntityIds the harbourRequestId2DataEntityIds to set
	 */
	public void setHarbourRequestId2DataEntityIds(
			HashMap<String, TreeSet<String>> harbourRequestId2DataEntityIds) {
		this.harbourRequestId2DataEntityIds = harbourRequestId2DataEntityIds;
	}

	/**
	 * @return the harbourRequestIds
	 */
	public TreeSet<String> getHarbourRequestIds() {
		return this.harbourRequestIds;
	}

	/**
	 * @param harbourRequestIds the harbourRequestIds to set
	 */
	public void setHarbourRequestIds(TreeSet<String> harbourRequestIds) {
		this.harbourRequestIds = harbourRequestIds;
	}

	/**
	 * @return the harbourRequestModels
	 */
	public HashMap<String, HarbourRequest> getHarbourRequestModels() {
		return this.harbourRequestModels;
	}

	/**
	 * @param harbourRequestModels the harbourRequestModels to set
	 */
	public void setHarbourRequestModels(
			HashMap<String, HarbourRequest> harbourRequestModels) {
		this.harbourRequestModels = harbourRequestModels;
	}

	/**
	 * @return the persistenceResourceModels
	 */
	public HashMap<String, PersistenceResource> getPersistenceResourceModels() {
		return this.persistenceResourceModels;
	}

	/**
	 * @param persistenceResourceModels the persistenceResourceModels to set
	 */
	public void setPersistenceResourceModels(
			HashMap<String, PersistenceResource> persistenceResourceModels) {
		this.persistenceResourceModels = persistenceResourceModels;
	}

	/**
	 * @return the senderId2dataSourceIds
	 */
	public HashMap<String, TreeSet<String>> getSenderId2DataSourceIds() {
		return this.senderId2DataSourceIds;
	}

	/**
	 * @param senderId2dataSourceIds the senderId2dataSourceIds to set
	 */
	public void setSenderId2dataSourceIds(
			HashMap<String, TreeSet<String>> senderId2dataSourceIds) {
		this.senderId2DataSourceIds = senderId2dataSourceIds;
	}

	/**
	 * @return the senderId2harbourRequestIds
	 */
	public HashMap<String, TreeSet<String>> getSenderId2HarbourRequestIds() {
		return this.senderId2HarbourRequestIds;
	}

	/**
	 * @param senderId2harbourRequestIds the senderId2harbourRequestIds to set
	 */
	public void setSenderId2harbourRequestIds(
			HashMap<String, TreeSet<String>> senderId2harbourRequestIds) {
		this.senderId2HarbourRequestIds = senderId2harbourRequestIds;
	}

	/**
	 * @return the senderModels
	 */
	public HashMap<String, Sender> getSenderModels() {
		return this.senderModels;
	}

	/**
	 * @param senderModels the senderModels to set
	 */
	public void setSenderModels(HashMap<String, Sender> senderModels) {
		this.senderModels = senderModels;
	}

	/**
	 * @return the unpersistedHarbourRequestIds
	 */
	public TreeSet<String> getUnpersistedHarbourRequestIds() {
		return this.unpersistedHarbourRequestIds;
	}

	/**
	 * @param unpersistedHarbourRequestIds the unpersistedHarbourRequestIds to set
	 */
	public void setUnpersistedHarbourRequestIds(
			TreeSet<String> unpersistedHarbourRequestIds) {
		this.unpersistedHarbourRequestIds = unpersistedHarbourRequestIds;
	}

	
	
	
	
	
	


}
